home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / stv.lha / STV / ISA / artifact / notifier.cls < prev    next >
Text File  |  1993-07-23  |  4KB  |  138 lines

  1.  
  2. " Notifier Window by Tom Wrensch & Gene Korienek
  3.  
  4.   The Notifier is a window that will pop up with 
  5.   some text in it.  Not a big deal, but its nice
  6.   for when a Menu message: won't do the trick
  7.   because theres too much information to put in
  8.   one line.
  9.  
  10.   The advantage of the notifier over using the
  11.   edit message in string is that it can take text
  12.   as either a string with embedded LF or CR's or
  13.   as an array of strings.  Also the notifier will
  14.   size itself appropriatly to the text it contains."
  15.  
  16.   There are two ways of opening a notifier:
  17.  
  18.         Notifier new openOn: SomeBigString. 
  19.         Notifier new openBeepOn: SomeBigString.
  20.  
  21.   The only difference is that the second one will beep
  22.   as the notifier is opening."!
  23.  
  24.  
  25. Object subclass: #Notifier
  26.   instanceVariableNames: 
  27.     'pane msg '
  28.   classVariableNames: ''
  29.   poolDictionaries: '' !
  30.  
  31. !Notifier class methods ! !
  32.  
  33.  
  34. !Notifier methods !
  35.  
  36. accept: aString from: aDispatcher
  37.         "This doesn't make sense for this application,
  38.          so ignore it"
  39.     ^true!
  40.  
  41. activateWindow
  42.         "Since notifiers are usualy activated only once,
  43.          update the pane so it displays the text of the
  44.          message instead of an empty string."
  45.     pane update!
  46.  
  47. initWindowSize
  48.         "Answer the initial window extent.  This is sized
  49.          based on the messages maximum line length and
  50.          number of lines, and of course the font used
  51.          to display the message."
  52.     | x y |
  53.  
  54.     " Get the X and Y sizes for the window "
  55.     x := (SysFont stringWidth: 'Notifier') + 6 +
  56.         (SysFont height * 3).
  57.     msg do: [:str |
  58.         x := x max: (TextFont stringWidth: str)].
  59.     x := x + 6.
  60.     y := SysFont height + 11 +
  61.         (TextFont height * msg size).
  62.  
  63.     " If the window is to big, make it half screen
  64.       and leave room for the scroll bar"
  65.     y > Display extent y ifTrue: [
  66.         y := Display extent y // 2.
  67.         x := x + 18].
  68.  
  69.     ^x @ y!
  70.  
  71. makeLines: aMessage
  72.         "Private - Answer the message as an array of lines."
  73.     | list stream |
  74.     (aMessage isKindOf: String)
  75.     ifTrue: [
  76.         list := OrderedCollection new.
  77.         stream := aMessage asStream.
  78.         [stream atEnd] whileFalse: [
  79.             list addLast: stream nextLine]]
  80.     ifFalse: [
  81.         (aMessage isKindOf: Collection)
  82.             ifTrue: [list := aMessage]
  83.             ifFalse: [list := Array with: '']].
  84.     ^list asArray!
  85.  
  86. makeTextPane
  87.         "Private - Create and answer the text
  88.          pane for the window."
  89.    ^TextPane new
  90.         model: self;
  91.         name: #text;
  92.         change: #accept:from:;
  93.         yourself!
  94.  
  95. makeTopPane
  96.         "Private - Create and answer the
  97.          top pane for this window applicaiton."
  98.     ^TopPane new
  99.         model: self;
  100.         label: 'Notifier';
  101.         minimumSize: 100@50;
  102.         rightIcons: #(collapse);
  103.         foreColor: 0;
  104.         backColor: 15;
  105.         yourself.!
  106.  
  107. openBeepOn: aMessage
  108.         "Open up the suggestor window and beep as
  109.          it opens to let the user know about it."
  110.     self openOn: aMessage withBeep: true!
  111.  
  112. openOn: aMessage
  113.         "Open up the suggestor window without beeping."
  114.     self openOn: aMessage withBeep: false!
  115.  
  116. openOn: aMessage withBeep: beepFlag
  117.         "Open up the suggestor window with the text
  118.          in aMessage and a beep if beepFlag is true."
  119.     | aTopPane |
  120.  
  121.     msg := self makeLines: aMessage.
  122.  
  123.     aTopPane := self makeTopPane.
  124.     pane := self makeTextPane.
  125.     aTopPane addSubpane: pane.
  126.  
  127.     beepFlag == true ifTrue: [Terminal bell].
  128.  
  129.     aTopPane dispatcher open scheduleWindow!
  130.  
  131. text
  132.         "Answer the text string to be displayed."
  133.     | stream |
  134.     stream := (String new: 0) asStream.
  135.     msg do: [:str |
  136.         stream nextPutAll: str; cr].
  137.     ^stream contents! !
  138.